#import "FDFeedCell.h"

@interface FDFeedCell ()


@property (nonatomic, strong)  UILabel *titleLabel;
@property (nonatomic, strong)  UILabel *contentLabel;
@property (nonatomic, strong)  UIImageView *contentImageView;
@property (nonatomic, strong)  UILabel *usernameLabel;
@property (nonatomic, strong)  UILabel *timeLabel;
@end

@implementation FDFeedCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    
}
//重写父类的初始化方法，根据需求添加自己的逻辑
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style  reuseIdentifier:reuseIdentifier];
    if ([reuseIdentifier isEqualToString:@"FDFeedCell"]) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:_titleLabel];
        
        _contentLabel= [[UILabel alloc] init];
        _contentLabel.textColor = [UIColor grayColor];
        _contentLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_contentLabel];
        
        _usernameLabel= [[UILabel alloc] init];
        _usernameLabel.textColor = [UIColor redColor];
        _usernameLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_usernameLabel];
        
        _timeLabel= [[UILabel alloc] init];
        _timeLabel.textColor = [UIColor greenColor];
        _timeLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_timeLabel];
        
        _contentImageView = [[UIImageView alloc]init];
        _contentImageView.contentMode = UIViewContentModeScaleAspectFit; //内容(image)撑开View
        [_contentImageView setAutoresizesSubviews:YES];
        [self.contentView addSubview:_contentImageView];
        
//        [self setupViewConstraints];
//        [self setNeedsUpdateConstraints];
//        [self updateConstraintsIfNeeded];
    }
    return self;
}

-(void)setupViewConstraints{
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
    }];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
    }];
    [_contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentLabel.mas_bottom).offset(30);
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentImageView.mas_bottom).offset(40);
        make.bottom.equalTo(self.contentView).offset(-50);
    }];
    [_usernameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_timeLabel);
        make.left.equalTo(_timeLabel.mas_right).offset(20);
        make.bottom.equalTo(self.contentView).offset(-50);
    }];
}

//重写布局方法，根据需求自己设置
-(void)updateConstraints{
    NSLog(@"updateConstraints");
//    [self setupViewConstraints];
    [super updateConstraints];
}
//-(void)layoutSubviews{
//  
//}


- (void)setEntity:(FDFeedEntity *)entity
{
    _entity = entity;
    
    self.titleLabel.text = entity.title;
    self.contentLabel.text = entity.content;
    self.contentImageView.image = entity.imageName.length > 0 ? [UIImage imageNamed:entity.imageName] : nil;
    self.usernameLabel.text = entity.username;
    self.timeLabel.text = entity.time;
}

@end
